package com.aaron.smartktv

import android.util.Log
import java.lang.ref.WeakReference

object GcWatcher {

    private var gcWatcher: WeakReference<GcWatcherInternal>? = null
    // 在你application启动的时候 init就行
    @JvmStatic
    fun init() {
        if (gcWatcher == null) {
            gcWatcher = WeakReference(GcWatcherInternal())
        } else {
            Log.e("内存回收", "内存回收监控已经初始化")
        }
    }

    class GcWatcherInternal {
        @kotlin.jvm.Throws(Throwable::class)
        protected fun finalize() {
            // 每次gc都会走这里 可以在这里统计你想要的次数/频率等信息
            Log.e("内存回收", "finalize回调，发生-内存回收")
            gcWatcher = WeakReference(GcWatcherInternal())

        }
    }
}